import React from 'react';
import ReactDOM from 'react-dom';
import {
    Router,
    hashHistory,
    Route, IndexRoute
} from 'react-router';
import {ApolloProvider} from 'react-apollo';
import ApolloClient, {createNetworkInterface} from 'apollo-client';

// 创建ApolloClient，设置GraphQL服务自定义地址
const networkInterface = createNetworkInterface('/_');
const client = new ApolloClient({networkInterface});

import {init} from './global';
init(); // 初始化全局变量

import App from './app';
import NotFound from './404';
import Home from './home';
import Dbms, * as dbms from './dbms';

// 路由定义和渲染
ReactDOM.render(
    <ApolloProvider client={client}>
        <Router history={hashHistory}>
            <Route path="/" component={App}>
                <IndexRoute component={Home}/>
                <Route path="/dbms" component={Dbms}>
                    <Route path=":conn/:db/:table" component={dbms.Table}>
                        <Route path="field" component={dbms.Field}/>
                        <Route path="record" component={dbms.Record}/>
                    </Route>
                </Route>
                <Route path="*" component={NotFound}/>
            </Route>
        </Router>
    </ApolloProvider>,
    document.getElementById('root')
);
